package day5.homework3;

import java.math.BigDecimal;

public class Calc {
    public Double number1;
    public Double number2;
    public String operator;

    public String calcValue() {
        BigDecimal value1 = new BigDecimal(number1.toString());
        BigDecimal value2 = new BigDecimal(String.valueOf(number2));
        if ("+".equals(operator)) return value1.add(value2).toString();
        if ("-".equals(operator)) return value1.subtract(value2).toString();
        if ("*".equals(operator)) return value1.multiply(value2).toString();
        if ("/".equals(operator)) return value1.divide(value2).toString();
        // divideAndRemainder方法返回2长度的数组，0位置数据为商，1位置数据为余
        if ("%".equals(operator)) return value1.remainder(value2).toString();
        return null;
    }
}
